<template>
  <div>
    <van-nav-bar title="信息填写" left-arrow @click-left="goBack" />
    <van-cell title="昵称" is-link :value="defaultInfo.nickname" />
    <van-cell v-if="defaultInfo.sex == 0" title="性别" is-link value="男" />
    <van-cell v-if="defaultInfo.sex == 1" title="性别" is-link value="女" />
    <van-cell v-if="defaultInfo.sex == 3" title="性别" is-link value="未知" />
    <van-cell title="出生日期" @click="showBirthdayPopup" is-link :value="currentDate | dateFormat" />
    <van-cell title="所在城市" @click="showCityPopup" is-link :value="city" />
    <van-cell title="学科" is-link value="学科" />
    <van-cell title="年级" is-link value="年级" />
    <van-button style="margin-top:100px;" type="warning" block>块级元素</van-button>

    <!-- 生日选择 -->
    <van-popup v-model="birthdayPopup" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择年月日"
        :min-date="minDate"
        :max-date="maxDate"
        @confirm="birthdaySure"
      />
    </van-popup>
    <!-- 城市选择 -->
    <van-popup v-model="cityPopup" position="bottom">
      <van-area @confirm="citySure" title="标题" :area-list="areaList" />
    </van-popup>
  </div>
</template>

<script>
import areaList from "../assets/city";
import { zzhUserInfo } from "../util/http";
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {},
  data() {
    return {
      defaultInfo: {},
      birthdayPopup: false,
      minDate: new Date(1995, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(),
      cityPopup: false,
      areaList: areaList,
      cityCode: "",
      city: "所在城市"
    };
  },
  computed: {},
  watch: {},
  methods: {
    async getUserInfo() {
      console.log(123);
      const res = await zzhUserInfo();
      console.log(res);
    },
    getDefaultInfo() {
      this.defaultInfo = JSON.parse(window.sessionStorage.getItem("user"));
      console.log(this.defaultInfo);
    },
    goBack() {
      this.$router.push("/setPassFirst");
    },
    showBirthdayPopup() {
      this.birthdayPopup = true;
    },
    birthdaySure() {
      console.log(this.currentDate);
    },
    showCityPopup() {
      this.cityPopup = true;
    },
    citySure(e) {
      var city = [];
      this.cityCode = e;
      this.cityPopup = false;
      this.cityCode.forEach(item => {
        console.log(item.name);
        city.push(item.name);
      });
      this.city = city.join(",");
    }
  },
  beforeCreate() {},
  created() {
    this.getUserInfo();
    // this.getDefaultInfo();
  },
  beforeMount() {},
  mounted() {}
};
</script> 
<style scoped>
</style>
